﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Agro.Services;
using Ninject;
using System.Text;
using Agro.Library;

namespace Agro.Web {
    public static class HtmlExtention {
        [Inject]
        private static IPermissionService PermissionService = new PermissionService();
        const string BUTTON_FORMAT = "<a onclick=\"{0}\" class=\"button green\"><span class=\"icon-botton\" style=\"background: url('/Content/16/{1}') no-repeat scroll 0px 4px;\"></span>{2}</a>";
        public static MvcHtmlString ButtonExt(this HtmlHelper htmlHelper, string text, string btnImg, string actionCode, string onclick) {
            CurrentUser user = new CurrentUser();
            if (!string.IsNullOrEmpty(actionCode) && (user.UserInfo == null || !PermissionService.HasPremission(user.UserInfo.User_ID.ToString(), actionCode))) {
                return new MvcHtmlString("");
            }
            string html = string.Format(BUTTON_FORMAT, onclick, btnImg, text);
            return new MvcHtmlString(html);
        }
    }
}